//
//  PictureTestViewController.swift
//  CTPhotoBrowser
//
//  Created by Andney Jack on 2021/2/26.
//

import UIKit

public class PictureTestViewController: UIViewController {
    override public func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white

        let actionButton = UIButton(frame: .zero)
        actionButton.layer.cornerRadius = 4
        actionButton.layer.masksToBounds = true
        actionButton.setTitle("关闭", for: .normal)
        actionButton.backgroundColor = RandomColor()
        actionButton.addTarget(self, action: #selector(buttonClick(_:)), for: .touchUpInside)
        view.addSubview(actionButton)

        actionButton.snp.makeConstraints { make in
            make.left.equalTo(view.snp.leftMargin).offset(30)
            make.top.equalTo(view.snp.topMargin).offset(40)
            make.width.equalTo(80)
            make.height.equalTo(44)
        }

        let imgView = UIImageView()
//        imgView.image = UIImage(named: "big_image", in: Bundle.main, compatibleWith: nil)

        if let path = Bundle.main.path(forResource: "big_image", ofType: "jpg") {
            if let img = UIImage(contentsOfFile: path) {
                imgView.image = img.ct_scaleToWidth(1000)
            }
        }

        view.addSubview(imgView)

        imgView.snp.makeConstraints { make in
            make.left.equalTo(view.snp.left)
            make.right.equalTo(view.snp.right)
            make.centerY.equalTo(view)
            make.height.equalTo(imgView.snp.width).multipliedBy(2.0 / 3.0)
        }
    }

    @objc func buttonClick(_ sender: UIButton) {
        dismiss(animated: true, completion: nil)
    }
}
